#ifndef PDOMPARSER_H
#define PDOMPARSER_H

#include <QtXml>


#include "earthquake_global.h"
#include "epoint.h"

#include <QObject>

class PDomParser : public QObject
{
public:

    PDomParser( void );

    ///////////////////////////////////////////
    // XML general files parser private methods
    ///////////////////////////////////////////

    // Legge il file intero e lo memorizza in una cache
    bool parseXmlFile(const QString &file_name,const QString &tag_root);

    // Scorre i figli dell'elemento fino a che non trova tag_name
    QString parseElementChildren(
            const QString &tag_name_list,
            bool *success);

    bool extractFromFileTo(const QString &file_name, ExaTextFormat format);
    // bool     parseFromFile(const QDomElement &element, EPoint &point);

    enum PDomParserErr
    {
            ErrOk                =   0,
            ErrFormatUnknown     =   1, // sospeso
            ErrXmlFileReadOnly   =   2,
            ErrXmlParsingContent =  10,
            ErrXmlParsingRoot    =  11,
            ErrXmlParsingNode    =  13,
            ErrXmlParsingText    =  14,
            ErrXmlParsingNodeL   =  15,
            ErrKmlCoordinatesLat = 101,
            ErrKmlCoordinatesLon = 102,
            ErrKmlCoordinatesEle = 103
    };

    QString getFileName() const;
    QString getFilePath() const;

    PDomParser::PDomParserErr getErr()    const;
                      QString getErrMsg() const;

private:
    QString m_file_name_path;
    QString m_file_name;

    PDomParserErr m_last_err;
          QString m_last_err_msg;
          QString m_content_str;

      QDomDocument m_doc;
      QDomElement m_root;

    // Scorre i figli dell'elemento fino a che non trova tag_name
    QDomElement m_parseElementChildren(
            const QDomElement &element,
            const QString &tag_name,
            bool *success);

    ///////////////////////////////////
    // KML files parser private methods
    ///////////////////////////////////
    // Legge il file tipo KML intero e lo memorizza in una cache
    bool m_parseKmlFile(const QString &file_name);

    // Prova a creare un elemento [EPoint]
    bool m_parseFromElement(const QDomElement &element,
                              EPoint &point);

};

#endif // PDOMPARSER_H
